<template>
  <div>
    <div class="header_search_nav search_form">
      <div class="ipt_left">
        <el-form ref="queryForm" :model="queryParams" label-width="80px">
          <el-row>
            <el-col :span="6">
              <el-form-item label="门店" prop="storeId">
                <el-select
                  v-model="queryParams.storeId"
                  placeholder="请选择"
                  filterable
                >
                  <el-option
                    v-for="(item, index) in $store.state.user.stores"
                    :key="index"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <div class="btn_right">
        <button class="btn1" @click="handleQuery">筛选</button>
        <button class="btn2" @click="resetQuery">重置</button>
      </div>
    </div>
    <div class="table_card">
      <div class="table_card_top">
        <span class="solid_left"></span>
        <div class="table_card_title">续费门店</div>
        <div class="op_right">
          <button
            class="primary_button"
            @click="WaitRenewal"
            style="width: 130px"
          >
            待续费门店({{ totals }})
          </button>
          <button class="primary_button" @click="NewUser">新增续费</button>
        </div>
      </div>

      <div class="table_list">
        <el-table :data="RenewalList" stripe style="width: 100%">
          <el-table-column prop="storeName" label="门店名称"> </el-table-column>
          <el-table-column prop="createTime" label="创建时间">
          </el-table-column>
          <el-table-column prop="storeExpireDay" label="续费时长">
          </el-table-column>
          <el-table-column prop="storeExpireUnit" label="续费单位">
            <template slot-scope="scope">
              <div>{{ storeExpireObj[scope.row.storeExpireUnit] }}</div>
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button size="mini" type="text" @click="DelRenewal(scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          :total="total"
          :page.sync="queryParams.pageNo"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>

      <!-- 新增续费 -->
      <el-dialog
        :visible.sync="RenewalVisible"
        width="500px"
        :title="title"
        class="no-dialog-padding"
        @close="RenewalCancel"
      >
        <span>
          <div class="source_box">
            <el-form
              :model="RenewalForm"
              :rules="RenewalRules"
              ref="RenewalForm"
              label-width="100px"
              class="demo-ruleForm"
            >
              <el-form-item label="门店" prop="storeId">
                <el-select
                  v-model="RenewalForm.storeId"
                  placeholder="请选择"
                  class="w-100"
                  filterable
                  :disabled="RenewaDisable === true"
                >
                  <el-option
                    v-for="(item, index) in WaitRenewalArray"
                    :key="index"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="续费时长" prop="storeExpireDay">
                <el-input-number
                  v-model="RenewalForm.storeExpireDay"
                  :min="0"
                  :max="1000"
                  :controls="false"
                  class="w-100 text-left"
                  :precision="0"
                ></el-input-number>
              </el-form-item>
              <el-form-item label="续费单位" prop="storeExpireUnit">
                <el-select
                  v-model="RenewalForm.storeExpireUnit"
                  placeholder="请选择"
                  class="w-100"
                >
                  <el-option
                    v-for="item in storeExpireList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-form>
          </div>
        </span>
        <span slot="footer" class="dialog-footer">
          <el-button class="cancel_btn" @click="RenewalCancel">取 消</el-button>
          <el-button
            type="primary"
            @click="RenewalSubmit"
            :loading="RenewalLoading"
            >确 定</el-button
          >
        </span>
      </el-dialog>

      <!-- 待续费门店 -->
      <el-dialog
        :visible.sync="WaitRenewalVisible"
        width="600px"
        title="待续费门店"
        class="no-dialog-padding"
        @close="WaitRenewalCancel"
      >
        <span>
          <div class="source_box">
            <el-table :data="WaitRenewalList" style="width: 100%">
              <el-table-column prop="name" label="门店"> </el-table-column>
              <el-table-column prop="storeExpireDate" label="有效期">
              </el-table-column>
              <el-table-column label="操作">
                <template slot-scope="scope">
                  <el-button size="mini" type="text" @click="NewUser(scope.row)"
                    >续费</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
            <pagination
              :total="totals"
              :page.sync="query.pageNo"
              :limit.sync="query.pageSize"
              @pagination="getWaitRenewal"
            />
          </div>
        </span>
        <span slot="footer" class="dialog-footer">
          <el-button class="cancel_btn" @click="WaitRenewalCancel"
            >取 消</el-button
          >
          <!-- <el-button
            type="primary"
            @click="WaitRenewalSubmit"
            :loading="WaitRenewalLoading"
            >确 定</el-button
          > -->
        </span>
      </el-dialog>
    </div>
  </div>
</template>
    
<script>
import { UpdateCategory } from "@/api/bpm/category";
import {
  createRenewalPage,
  getRenewalPage,
  DeleteRenewalPage,
  getWaitRenewalMoney,
} from "@/api/bpm/Renewal";

export default {
  name: "EryuoaStoreCategoryList",
  data() {
    return {
      RenewalForm: {
        storeExpireDay: "", // 续费时长
        storeExpireUnit: "", // 续费单位
        storeId: "",
      },
      RenewalRules: {
        storeId: [{ required: true, message: "请选择门店", trigger: "blur" }],
        storeExpireDay: [
          { required: true, message: "请输入续费时长", trigger: "blur" },
        ],

        storeExpireUnit: [
          { required: true, message: "请选择续费单位", trigger: "change" },
        ],
      },
      RenewalVisible: false, // 新增续费
      RenewalList: [], // 续费门店数据
      loading: false,

      WaitRenewalLoading: false,
      WaitRenewalVisible: false,
      WaitRenewalList: [], // 待续费
      WaitRenewalArray:[], // 待续费弹框数据
      RenewaDisable: false,

      title: "",
      total: 0,
      totals: 0,
      RenewalLoading: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
      },
      // 查询参数
      queryParam: {
        pageNo: 1,
        pageSize: 10,
      },

      query: {
        pageNo: 1,
        pageSize: 10,
      },

      storeExpireObj: {
        Y: "年",
        M: "月",
        D: "天",
      },

      storeExpireList: [
        {
          value: "Y",
          label: "年",
        },
        {
          value: "M",
          label: "月",
        },
        {
          value: "D",
          label: "天",
        },
      ],
    };
  },

  created() {
    this.getList();
    this.getWaitRenewal();
  },

  mounted() {},

  methods: {
    getWaitRenewal() {
      this.WaitRenewalLoading = true;
      getWaitRenewalMoney(this.query)
        .then((res) => {
          this.WaitRenewalLoading = false;
          const { code, data } = res;
          if (code === 0) {
            this.WaitRenewalList = data.list;
            this.totals = data.total;
          }
        })
        .catch((err) => {
          this.WaitRenewalLoading = false;
        });
    },

    getPage() {
      this.WaitRenewalLoading = true;
      getWaitRenewalMoney({
        pageNo: 1,
        pageSize: 9999,
      })
        .then((res) => {
          this.WaitRenewalLoading = false;
          const { code, data } = res;
          if (code === 0) {
            this.WaitRenewalArray = data.list;
          }
        })
        .catch((err) => {
          this.WaitRenewalLoading = false;
        });
    },

    WaitRenewal() {
      this.WaitRenewalVisible = true;
    },

    WaitRenewalCancel() {
      this.WaitRenewalVisible = false;
      this.query.pageNo = 1;
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParam.pageNo = 1;
      this.getLists();
    },

    // 续费门店列表
    getList() {
      this.loading = true;
      getRenewalPage(this.queryParams)
        .then((res) => {
          this.loading = false;
          const { code, data } = res;
          if (code === 0) {
            this.RenewalList = data.list;
            this.total = data.total;
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },

    RenewalCancel() {
      this.resetFormData("RenewalForm");
      this.RenewalLoading = false;
      this.$nextTick(() => {
        this.RenewalVisible = false;
      });
    },

    // 筛选
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetFormData("queryForm");
      // this.queryParams.localDate = dayDataTime("obj").str;
      this.handleQuery();
    },

    // 新增续费
    RenewalSubmit() {
      this.RenewalLoading = true;
      this.$refs["RenewalForm"].validate((valid) => {
        // console.log(this.RenewalForm);
        createRenewalPage(this.RenewalForm)
          .then((res) => {
            this.RenewalLoading = false;
            const { code } = res;
            if (code === 0) {
              this.RenewalCancel();
              this.$message.success("操作成功");
              this.getList();
            }
          })
          .catch((err) => {
            this.RenewalLoading = false;
          });
      });
    },

    // 新增续费
    CreateCategorys() {},

    // 编辑
    UpdateCategorys() {
      let RenewalForm = JSON.parse(JSON.stringify(this.RenewalForm));
      UpdateCategory(RenewalForm)
        .then((res) => {
          const { code } = res;
          if (code === 0) {
            this.RenewalCancel();
            this.$message.success("操作成功");
            this.getList();
          }
        })
        .catch((err) => {});
    },

    // 新建
    NewUser(row) {
      this.RenewalVisible = true;
      this.title = "新增续费";
      if (!!row.id) {
        this.RenewalForm.storeId = row.id;
        this.RenewalForm.storeName = row.storeName;
        this.RenewaDisable = true;
      } else {
        this.RenewaDisable = false;
      }

      this.getPage();
    },

    // 表单重置
    resetFormData(formName) {
      this.$refs[formName].resetFields();
    },

    // 删除用户
    DelRenewal(row) {
      this.$confirm("续费记录删除后将无法撤回, 是否删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          DeleteRenewalPage({ id: row.storeExpireId })
            .then((res) => {
              const { code } = res;
              if (code === 0) {
                this.getList();
                this.$modal.msgSuccess("操作成功");
              }
            })
            .catch(() => {});
        })
        .catch(() => {});
    },
  },
};
</script>
    
    <style lang="scss" scoped>
.w-200 {
  width: 200px;
  background: #ffffff;
  border-radius: 4px;
}

.client_name {
  font-size: 14px;
  font-weight: 400;
  color: #0052d9;
}

.give {
  height: 40px;
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
  margin-top: 40px;
  line-height: 40px;
}

.el-form-item {
  margin-bottom: 20px;
}

.recharge_form {
  padding: 10px 24px;
}

.memberName {
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
}
.el_row_item {
  margin-bottom: 10px;
}
.el_row_date {
  margin-top: 20px;
}
.el_row_reason {
  margin-top: 10px;
}

.el_row_date {
  .el-form-item {
    margin-bottom: 0px;
  }
}
.source_box {
  margin: 10px 24px;
}
</style>
    
  
  